﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DotNet.Business;
using DotNet.Model;
using DotNet.Common;
using System.Collections.Generic;
public partial class Admin_clrearEmptyDir : System.Web.UI.Page
{
    public productBll pBll = new productBll();
    protected void Page_Load(object sender, EventArgs e)
    {        
      
    }       
    public void Clear() 
    {
        try
        {
            string path = Server.MapPath(@"~") + @"\UploadFiles\productUpload\";
            HtmlControls.Start();
            string[] dirs = System.IO.Directory.GetDirectories(path);
            IList<product> pList = pBll.GetModel();
            int count = dirs.Length;            
            for (int i = 0; i < count; i++)
            {
                bool bo = false;
                foreach (product pro in pList)
                {
                    if (bo)
                    {
                        break;
                    }
                    if (dirs[i].Substring(dirs[i].LastIndexOf('\\') + 1).Equals(pro.Productmodel))
                    {
                        bo = true;
                    }
                }
                if (!bo)
                {

                    System.IO.Directory.Delete(dirs[i], true);

                }
                HtmlControls.Roll("进度：", Convert.ToInt32(Convert.ToDouble(i) / Convert.ToDouble(count) * 100));
            }
            HtmlControls.Roll("进度：", 100);     
        }
        catch (Exception)
        {

            Response.Write("存在文件无法删除，操作中断！");
        }
        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {       
        Clear();
        GC.ReRegisterForFinalize(this);
        GC.WaitForPendingFinalizers();
        Response.End();
       
        
    }
}
